home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Imaging / MouseTrap < prev    next >
Encoding:
Text File  |  1998-11-13  |  1.2 KB  |  66 lines  |  [TEXT/AKu?]

  1. property kasSize : {128, 128}
  2. property kasScale : {4, 4}
  3. property kasName : "MouseTrap"
  4. property kasRefreshInterval : 1
  5.  
  6. global gasDrawWin
  7. global gdx, gdy
  8. global gasPos
  9.  
  10.  
  11. on run
  12.     pfLoad()
  13.     
  14.     set gasDrawWin to ¬
  15.         display drawing titled kasName ¬
  16.             with dimensions kasSize ¬
  17.             located at gasPos
  18.     
  19.     set gdx to (item 1 of kasSize) / 2 / (item 1 of kasScale)
  20.     set gdy to (item 2 of kasSize) / 2 / (item 2 of kasScale)
  21.     
  22.     idle
  23. end run
  24.  
  25.  
  26. on idle
  27.     -- Find mouse
  28.     set mPos to pointer location of (input state)
  29.     set mBox to {(item 1 of mPos) - gdx, (item 2 of mPos) - gdy, (item 1 of mPos) + gdx, (item 2 of mPos) + gdy}
  30.     
  31.     -- Get picture
  32.     set mPic to capture picture inside of mBox
  33.     
  34.     -- Draw it (don't need scale parameter, since we are using "inside of" to scale to full window)
  35.     draw a picture into gasDrawWin ¬
  36.         using data mPic ¬
  37.         inside of {0, 0, item 1 of kasSize, item 2 of kasSize} ¬
  38.         without recording
  39.     
  40.     return kasRefreshInterval
  41. end idle
  42.  
  43.  
  44. on quit
  45.     set gasPos to screen location of ¬
  46.         (display drawing gasDrawWin with disposal)
  47.     
  48.     pfSave()
  49.     
  50.     return (continue quit)
  51. end quit
  52.  
  53.  
  54. on pfLoad()
  55.     try
  56.         set gasPos to load preference named kasName
  57.     on error
  58.         set gasPos to {-1, -1}
  59.     end try
  60. end pfLoad
  61.  
  62.  
  63. on pfSave()
  64.     save preference gasPos named kasName
  65. end pfSave
  66.